package 剑指offer;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @description:
 * @author: ywk
 * @date: 2021-04-10
 */
public class 数组中只出现一次的数 {
    public static int foundOnceNumber(int[] arr, int k) {
        // write code here
        HashMap<Integer, Integer> map = new HashMap();
        for (int i = 0; i < arr.length; i++) {
            map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
        }
        Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
        for (Map.Entry<Integer, Integer> entry : entries) {
            if (entry.getValue() == 1) {
                return entry.getKey();
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(foundOnceNumber(new int[]{5, 4, 1, 1, 5, 1, 5}, 3));
    }

}
